/*
 * @Author: wangming
 * @Date: 2021-12-22 14:25:21
 * @LastEditors: wangming
 * @LastEditTime: 2021-12-22 15:25:11
 * @FilePath: /hanma-application-designer-fed/src/components/HmPermission/index.js
 * @Description: 
 */
import HmPermissionLayout from './HmPermissionLayout'
import HmPermissionButton from './HmPermissionButton'

/**
 * 标签解析
 * 权限组件hm-permission-button、hm-permission-layout
 * id支持小写字母、数字、“_” 必要属性
 * name支持中文、小写字母、数字、“_” 必要属性
 * @param {*} json 
 */
function tagsParse(json = '') {
  const reg1 = /<(hm-permission-button|HmPermissionButton|HmPermissionLayout|hm-permission-layout)\s+id=\\?"(\w+)\\?"\s+name=\\?"([\u4e00-\u9fa5\w]+)\\?"/g
  const reg2 = /<(hm-permission-button|HmPermissionButton|HmPermissionLayout|hm-permission-layout)\s+id=\\?"(\w+)\\?"\s+name=\\?"([\u4e00-\u9fa5\w]+)\\?"/
  const result = json.match(reg1) || []
  const elements = result.map(element => {
    const props = element.match(reg2)
    return {
      tag: props[1],
      id: props[2],
      name: props[3]
    }
  });
  return elements
}

export {
  HmPermissionLayout,
  HmPermissionButton,
  tagsParse
}